<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>父子组件之间的访问-父访问子</title>
</head>

<body>
    <script src="/js/vue.js"></script>
    <div id="app">
        <p>{{msg}}</p>
        <cpn></cpn>
        <cpn ref="aaa"></cpn>
        <cpn></cpn>

        <button @click="btnClick">click</button>
    </div>

    <template id="cpnT">
        <div>子组件内容</div>
    </template>

    <script>
        const cpn = {
            template:`#cpnT`
        }


        //父组件
        let app = new Vue({
            el: "#app",
            data: {
                msg: 'hello world'
            },
            components:{
                cpn
            },
            methods:{
                btnClick(){
                    // 1. $children方法
                    // console.log(this.$children[0]);
                    // for(const argument of this.$children){
                    //     console.log(argument);
                    // }

                    // 2. $refs
                    console.log(this.$refs.aaa);    

                }
            }
        })
    </script>
</body>

</html>